<template>
  <div class="container">
    <!-- 表单筛选区域 -->
    <el-form inline>
      <el-form-item label="标题">
        <el-input
          size="small"
          placeholder="请输入"
        />
      </el-form-item>
      <el-form-item label="分类">
        <el-input
          size="small"
          placeholder="请输入"
        />
      </el-form-item>
      <el-form-item label="时间">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择日期" style="width: 100%;" />
        </el-col>
        <el-col class="line" :span="2">-</el-col>
        <el-col :span="11">
          <el-time-picker placeholder="选择时间" style="width: 100%;" />
        </el-col>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          size="small"
        >搜索</el-button>
        <el-button size="small">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作区域 -->
    <el-row type="flex" justify="space-between" align="middle">
      <!-- 左侧 -->
      <div class="left">
        <el-button
          type="primary"
          plain
          size="small"
          icon="el-icon-plus"
          @click="addfn"
        >新增</el-button>
        <el-button type="warning" size="small" plain icon="el-icon-download">导出</el-button>
      </div>
      <!-- 右侧 -->
      <div class="right">右侧区域</div>
    </el-row>
    <br>
    <!-- 表格区域 -->
    <el-table border :data="list">
      <el-table-column prop="id" label="ID" width="66" />
      <el-table-column prop="title" label="标题" width="280" />
      <el-table-column prop="catename" label="分类名" />
      <el-table-column prop="pic" label="图片">
        <template slot-scope="{row}">
          <img :src="'http://124.223.14.236:8060/' + row.pic" height="80" alt="">
        </template>
      </el-table-column>
      <el-table-column prop="create_date" label="创建时间">
        <template slot-scope="{row}">
          {{ row.create_date | formatDate }}
        </template>
      </el-table-column>
      <el-table-column prop="ishot" label="是否推荐">
        <template slot-scope="{row}">
          <el-switch
            :value="row.ishot===1"
          />
        </template>
      </el-table-column>
      <el-table-column prop="istop" label="是否置顶">
        <template slot-scope="{row}">
          <el-switch
            :value="row.istop===1"
          />
        </template>
      </el-table-column>
      <el-table-column prop="status" label="文章状态">
        <template slot-scope="{row}">
          <el-tag>{{ row.status===2?'待审核':'已审核' }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="280">
        <template slot-scope="{ row }">
          <el-button
            type="primary"
            size="small"
            icon="el-icon-edit"
            circle
            @click="editRow(row.id)"
          />
          <el-button
            type="danger"
            size="small"
            icon="el-icon-delete"
            circle
            @click="delRow(row.id)"
          />
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination
      :current-page="page"
      :page-sizes="[2, 5, 7 , 10]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      background=""
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import { getUserInfoAPI, deleteUserInfoAPI } from '@/api/article'
export default {
  data() {
    return {
      start_time: '',
      end_time: '',
      title: '',
      cateid: '',
      page: 1,
      limit: 5,
      list: [],
      total: 0
    }
  },
  created() {
    this.UserList()
  },
  methods: {
    async  UserList() {
      const res = await getUserInfoAPI({
        start_time: this.start_time,
        end_time: this.end_time,
        title: this.title,
        cateid: this.cateid,
        page: this.page,
        limit: this.limit
      })
      console.log(res)
      this.list = res.data.data
      this.total = res.data.count
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.UserList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.page = val
      this.UserList()
    },
    delRow(id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        const res = await deleteUserInfoAPI(id)
        console.log(res)
        this.$message.success('删除成功')
        this.UserList()
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    addfn() {
      this.$router.push('/substance/addarticle')
    }
  }
}
</script>
<style scoped>
.container {
padding: 50px 20px 0 20px;
}
</style>
